home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Catalog Service Access Module / DTS Sample CSAM / Src / DTSSampleCSAM.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-02  |  12.8 KB  |  503 lines  |  [TEXT/KAHL]

  1. /*
  2.  * DTSSampleCSAM.h
  3.  * Copyright © 1992-93 Apple Computer Inc. All Rights Reserved.
  4.  */
  5. #ifndef __DTSSampleCSAM__
  6. #define __DTSSampleCSAM__
  7. #ifdef REZ
  8. #define IsResource        1
  9. #else
  10. #define IsResource        0
  11. #endif
  12.  
  13. #if IsResource == 0
  14. #include <OCETemplates.h>
  15. #include <Files.h>
  16. #include <OSUtils.h>
  17. #include <ToolUtils.h>
  18. #include <Devices.h>
  19. #include <Types.h>
  20. #include <Aliases.h>
  21. #include <Memory.h>
  22. #include <Errors.h>
  23. #include <Icons.h>
  24. #include <Resources.h>
  25. #include <OCE.h>
  26. #include <OCEErrors.h>
  27. #include <OCEAuthDir.h>
  28. #include "Audit.h"
  29. #include "DETUtilities.h"
  30. #endif
  31.  
  32. /*
  33.  * This should match the latest AOCE release that this was tested with.
  34.  */
  35. #define kMajorVersion                    1
  36. #define kMinorVersion                    0
  37. #define kReleaseStage                    final            /* In <SysTypes.r>        */
  38. #define kPreReleaseNumber                0
  39. #define kReleaseVersionString            "1.0"
  40. /*
  41.  * MPW defines this in the MakeFile. Define it here for Think C,
  42.  * and make sure it's correct for MPW.
  43.  */
  44. #ifndef kCSAMCreatorID
  45. #define kCSAMCreatorID                    'Pdsm'
  46. #elif kCSAMCreatorID != 'Pdsm'
  47.     << error, the above won't work >>
  48. #endif
  49. /*
  50.  * kTemplateName is the name (user-visible) of the CSAM. It is really only used by
  51.  * DTSSampleCSAMTemplate.r, but is defined here so that it can be included in the
  52.  * Creator resource. kTemplateName is also used by AuthAddToLocalIdentityQueue.
  53.  * Note that it is constant C-string. It must be duplicated as MPW Rez does not
  54.  * support token pasting.
  55.  */
  56. #define kTemplateName                    "DTS Sample CSAM"
  57. #define pTemplateName                    "\pDTS Sample CSAM"    /* Thanks MPW    */
  58.  
  59.  
  60. #if TRUE != 1
  61. #define TRUE        1
  62. #define FALSE        0
  63. #endif
  64.  
  65. /*
  66.  * Constants for the CSAM template. These are used by the C and Rez modules. They
  67.  * assume the following directory structure:
  68.  *    :...:DTSSampleCSAM ƒ
  69.  *            MakeFile
  70.  *            DTS Sample Icons
  71.  *            Src
  72.  *                DTSSampleCSAM.h
  73.  *                All .c .h .r
  74.  *            Obj
  75.  *                All objects and linked code segments are written here
  76.  */
  77.  
  78. /*
  79.  * These are used in the Rez and DTS_CSAMTemplate.c files.
  80.  */
  81. #define kCSAMAspect                        kDETFirstID
  82. #define kCSAMInfoPage                    kDETSecondID
  83.  
  84. #define prCreatePDButton                (kSAMFirstDevProperty + 1)
  85. #define prHasCatalog                    (kSAMFirstDevProperty + 2)
  86. #define prPDAlias                        (kSAMFirstDevProperty + 3)
  87.  
  88. /*
  89.  * STR# kCSAMPromptStrings has prompt strings used in DTS_CSAMTemplate.c
  90.  */
  91. #define    kCSAMPromptStrings                128
  92. #define kNewPDPrompt                    1
  93. #define kNewPDName                        2
  94.  
  95. /*
  96.  *    General Constants 
  97.  */
  98. #define kIconID        (kCSAMAspect + kDETAspectMainBitmap)
  99. #define kDriverName    128
  100. #define kCSAMName    129                    /* GetString(kCSAMName) has CSAM name    */
  101. /*
  102.  * The attribute type in which we store the alias to the Personal Catalog associated
  103.  * with this Sample Catalog. Unfortunately, storing it in the resource file doesn't
  104.  * seem to work (probably because the current resource file is pointing to the
  105.  * wrong place). Note that it is a C string. AddCatalog.c converts it to an RString.
  106.  */
  107. #define kPDAliasAttrTypeBody            "Personal Catalog Alias"
  108.  
  109. /*
  110.  * These are the capabilities we provide: the application programmer accesses these
  111.  * by calling Gestalt. The actual values are specific to the particular CSAM. For
  112.  * this sample, we just copied the values from the Personal Catalog that the CSAM
  113.  * shadows.
  114.  *
  115.  * Note: we also suppor kSupportsFindRecordMask -- this is handled internally
  116.  * to the CSAM by enumerating through the personal catalog.
  117.  */
  118. #define kMyFeatures    (                                    \
  119.         kSupportsRecordCreationIDMask                    \
  120.         + kSupportsAttributeCreationIDMask                \
  121.         + kSupportsMatchAllMask                            \
  122.         + kSupportsBeginsWithMask                        \
  123.         + kSupportsExactMatchMask                        \
  124.         + kSupportsOrderedEnumerationMask                \
  125.         + kCanSupportNameOrderMask                        \
  126.         + kCanSupportTypeOrderMask                        \
  127.         + kSupportSortBackwardsMask                        \
  128.         + kSupportsEnumerationContinueMask                \
  129.         + kSupportsLookupContinueMask                    \
  130.         + kSupportsEnumerateAttributeTypeContinueMask    \
  131.         + kSupportsEnumeratePseudonymContinueMask        \
  132.         + kSupportsAliasesMask                            \
  133.         + kSupportsPseudonymsMask                        \
  134.         + kSupportsFindRecordMask                        \
  135.     )
  136.  
  137. #if IsResource == 0
  138. #ifndef DEBUG_LOG
  139. #define DEBUG_LOG    (kReleaseStage <= betaStage)
  140. #endif
  141. #define kNumIcons            6
  142. #define kAliasBufferSize    0x800
  143. #define kMyAccessMask        (        \
  144.         kSeeMask                    \
  145.         + kAddMask                    \
  146.         + kDeleteMask                \
  147.         + kChangeMask                \
  148.         + kRenameMask                \
  149.     )
  150. #define ioBusy                (1)
  151.  
  152. /*
  153.  * Our icons are defined by this structure. A vector of these is in our private
  154.  * driver control block structure.
  155.  */
  156. typedef struct IconInfo {
  157.     Handle                iconData;
  158.     ResType                iconType;
  159.     unsigned short        iconLength;
  160. } IconInfo, *IconInfoPtr;
  161.  
  162. /*
  163.  * This is a linked list of personal catalog files. It is a standard operating
  164.  * system queue. One of these is created for each catalog served by this CSAM.
  165.  */
  166. typedef struct CatalogInfo {
  167.     QElemPtr            qLink;                /* Next CatalogInfo element        */
  168.     short                qType;                /* Unused                        */
  169.     short                refNum;
  170.     CreationID            creationID;
  171.     DirDiscriminator    discriminator;
  172.     DirectoryName        directoryName;
  173. } CatalogInfo, *CatalogInfoPtr;
  174.  
  175. /*
  176.  * This is stored in the driver control block.
  177.  */
  178. typedef struct DTSSampleCSAMInfo {
  179.     DirParamBlock        dirParamBlock;        /* For internal asynch calls    */
  180.     DirEnumSpec            enumSpec;            /* For Find Record calls */
  181.     QHdr                requestQueueHdr;    /* Queue of pending requests    */
  182.     QHdr                catalogQHdr;        /* Queue of active catalogs        */
  183.     IconInfo            icons[kNumIcons];    /* -> Icon handles                */
  184. #ifdef THINK_C
  185.     long                originalA4;            /* A4 when CSAM was opened        */
  186. #endif
  187. #if DEBUG_LOG
  188.     AuditPtr            auditPtr;        /* DEBUG    */
  189. #endif
  190. } DTSSampleCSAMInfo, *DTSSampleCSAMInfoPtr;
  191.  
  192. /*
  193.  * All functions refer to certain "global" information
  194.  * by defining the following local variables. INFO
  195.  * is the driver's private data block (in DCTL.dCtlStorage)
  196.  */
  197. #define PARAM        (*pb)                /* Caller parameter record    */
  198. #define STATUS        (PARAM.header.ioResult)
  199. #define INFO        (*infoPtr)            /* CSAM private variables    */
  200.  
  201. #if DEBUG_LOG
  202. /*
  203.  * No side-effects for these -- I'm too lazy to add local variables.
  204.  */
  205. #define LogText(who, what)    \
  206.     Audit(INFO.auditPtr, who, kAuditFormatString, what)
  207. #define LogTextX(who, what) \
  208.     Audit(GetAuditPtr(kCSAMCreatorID), who, kAuditFormatString, what)
  209. #define LogStatusX(who, status, msg) do {                \
  210.         if (status != noErr) {                            \
  211.             AuditStatusString(                            \
  212.                 GetAuditPtr(kCSAMCreatorID),            \
  213.                 who,                                    \
  214.                 status,                                    \
  215.                 msg                                        \
  216.             );                                            \
  217.         }                                                \
  218.     } while (0)
  219. #define LogStatus(who, status, msg)    do {                \
  220.         if (status != noErr) {                            \
  221.             AuditStatusString(                            \
  222.                 INFO.auditPtr,                            \
  223.                 who,                                    \
  224.                 status,                                    \
  225.                 msg                                        \
  226.             );                                            \
  227.         }                                                \
  228.     } while (0)
  229. #define LogError(who, status) do {                        \
  230.         if (status != noErr) {                            \
  231.             AuditStatusLocation(INFO.auditPtr, who, status); \
  232.         }                                                \
  233.     } while (0)
  234. #define LogErrorX(who, status) do {                        \
  235.         if (status != noErr) {                            \
  236.             AuditStatusLocation(                        \
  237.                 GetAuditPtr(kCSAMCreatorID), who, status); \
  238.         }                                                \
  239.     } while (0)
  240. #define AuditRString(auditPtr, who, rString) (            \
  241.         Audit((auditPtr), (who), kAuditFormatString,    \
  242.             OCERToPString((RString *) (rString)))        \
  243.     )
  244. #define LogRStringX(who, rString) (                        \
  245.         AuditRString(                                    \
  246.             GetAuditPtr(kCSAMCreatorID),                \
  247.             who,                                        \
  248.             rString                                        \
  249.         )                                                \
  250.     )
  251. #define LogRString(who, rString) (                        \
  252.         AuditRString(                                    \
  253.             INFO.auditPtr,                                \
  254.             who,                                        \
  255.             rString                                        \
  256.         )                                                \
  257.     )
  258. /*
  259.  * Interface to the Audit subroutine (debugging). Note: these routines
  260.  * use stack space (temporarily).
  261.  */
  262. void
  263. AuditLookupGetPB(
  264.         DirParamBlock            *pbPtr
  265.     );
  266. void
  267. AuditRecordList(
  268.         AuditPtr                auditPtr,
  269.         RecordIDPtr                *aRecordList,
  270.         unsigned long            recordIDCount
  271.     );
  272. void
  273. AuditAttributeTypeList(
  274.         AuditPtr                auditPtr,
  275.         AttributeTypePtr        *attrTypeList,
  276.         unsigned long            attrTypeCount
  277.     );
  278. void
  279. AuditRecordID(
  280.         AuditPtr                auditPtr,
  281.         RecordIDPtr                recordIDPtr
  282.     );
  283. void
  284. AuditPackedRLIPtr(
  285.         AuditPtr                auditPtr,
  286.         PackedRLIPtr            rli
  287.     );
  288. void
  289. AuditPath(
  290.         AuditPtr                auditPtr,
  291.         PackedPathNamePtr        thePath
  292.     );
  293. #define AuditAttributeType(auditPtr, attributeTypePtr)    \
  294.     AuditRString(auditPtr, 'Attr', attributeTypePtr)
  295. void
  296. AuditLocalRecordID(
  297.         AuditPtr                auditPtr,
  298.         LocalRecordIDPtr        localRecordIDPtr
  299.     );
  300. #else
  301. #define LogText(who, what)                    /* Nothing    */
  302. #define LogTextX(who, what)                    /* Nothing    */
  303. #define LogStatusX(who, status, msg)        /* Nothing    */
  304. #define LogStatus(who, status, msg)            /* Nothing    */
  305. #define LogError(who, status)                /* Nothing    */
  306. #define LogErrorX(who, status)                /* Nothing    */
  307. #define LogRStringX(who, rString)            /* Nothing    */
  308. #define LogRString(who, rString)            /* Nothing    */
  309. #define AuditLookupGetPB(pbPtr)                /* Nothing    */
  310. #define AuditRecordList(p, a, r)            /* Nothing    */
  311. #define AuditAttributeTypeList(a, t, c)        /* Nothing    */
  312. #define AuditRecordID(a, r)                    /* Nothing    */
  313. #define AuditPackedRLIPtr(a, r)                /* Nothing    */
  314. #define AuditPath(a, p)                        /* Nothing    */
  315. #define AuditAttributeType(a, p)            /* Nothing    */
  316. #define AuditLocalRecordID(a, p)            /* Nothing    */
  317. #endif
  318.  
  319. /*
  320.  * Prototypes
  321.  */
  322. /*
  323.  * DisableInterrupts and EnableInterrupts manipulate the 68000 status register.
  324.  * They are expanded inline.
  325.  *
  326.  * unsigned short DisableInterrupts(void) {
  327.  *        asm {
  328.  *            move        sr,d0
  329.  *            move        #0x2600,sr
  330.  *        }
  331.  */
  332. unsigned short DisableInterrupts(void) = { 0x40C0, 0x46FC, 0x2600 };
  333. #ifdef THINK_C
  334. /*
  335.  * Since Think C has a real inline assembler, we can save one or two instructions.
  336.  * Nerd fun.
  337.  */
  338. #define EnableInterrupts(saveSR) asm {            \
  339.             move        saveSR,sr                \
  340.         }
  341. #else
  342. /*
  343.  * Even though the saveSR argument is a short, we must declare the function as a
  344.  * long so that both Think and MPW generate the same code. Otherwise, Think pushes
  345.  * a short and 2(sp) addresses the wrong value. (Guess how I discovered this.)
  346.  * Using the Think C inline defined above also eliminates the problem.
  347.  *
  348.  * void EnableInterrupts(unsigned long saveSR) {
  349.  *        asm {
  350.  *            move        2(sp),sr
  351.  *        }
  352.  */
  353. void EnableInterrupts(unsigned long saveSR) = { 0x46EF, 0x0002 };
  354. #endif
  355.  
  356.  
  357. /*
  358.  * These are calls into our routines from the driver glue.
  359.  *        paramBlock        User I/O parameter block
  360.  *        devCtlEnt        Driver control block
  361.  */
  362. extern OSErr                OpenDRVR(
  363.         CntrlParam                *paramBlock,
  364.         DCtlPtr                    devCtlEnt
  365.     );
  366. extern OSErr                PrimeDRVR(
  367.         CntrlParam                *paramBlock,
  368.         DCtlPtr                    devCtlEnt
  369.     );
  370. extern OSErr                ControlDRVR(
  371.         CntrlParam                *paramBlock,
  372.         DCtlPtr                    devCtlEnt
  373.     );
  374. extern OSErr                StatusDRVR(
  375.         CntrlParam                *paramBlock,
  376.         DCtlPtr                    devCtlEnt
  377.     );
  378. extern OSErr                CloseDRVR(
  379.         CntrlParam                *paramBlock,
  380.         DCtlPtr                    devCtlEnt
  381.     );
  382. /*
  383.  * Add the CSAM to the authentication manager's notification queue.
  384.  */
  385. OSErr                        InitAuthNotificationQueue(
  386.         register DTSSampleCSAMInfoPtr    infoPtr
  387.     );
  388.  
  389. /*
  390.  * CSAM Callbacks
  391.  */
  392. pascal OSErr                CSAM_DSProc(
  393.         DTSSampleCSAMInfoPtr    infoPtr,
  394.         DirParamBlockPtr        pb,
  395.         Boolean                    async
  396.     );
  397. pascal OSErr                CSAM_DSParseProc(
  398.         DTSSampleCSAMInfoPtr    infoPtr,
  399.         DirParamBlockPtr        pb,
  400.         Boolean                    async
  401.     );
  402. /*
  403.  * Utility
  404.  */
  405. OSErr                        GetCSAMIcon(
  406.         DTSSampleCSAMInfoPtr    infoPtr,
  407.         short                    i
  408.     );
  409.  
  410. QElemPtr                    DequeueFirst(
  411.         QHdrPtr                    theQueue
  412.     );
  413. void                        CallCompletion(
  414.         ParmBlkPtr                pb
  415.     );
  416.  
  417. void                        DirParseCommon(
  418.         DTSSampleCSAMInfoPtr    infoPtr,
  419.         DirParamBlockPtr        pb,
  420.         Boolean                    async
  421.     );
  422. void                        ProcessPDCommands(
  423.         DTSSampleCSAMInfoPtr    infoPtr,
  424.         DirParamBlockPtr        pb,
  425.         Boolean                    async
  426.     );
  427.  
  428. /*
  429.  * Callbacks
  430.  */
  431. pascal Boolean                MyForEachEnumSpec(
  432.         long                    userPB,
  433.         const DirEnumSpec        *enumSpecPtr
  434.     );
  435. pascal Boolean                MyForEachRecordID(
  436.         long                    userPB,
  437.         const RecordID            *rid
  438.     );
  439. pascal Boolean                MyForEachLookupRecordID(
  440.         long                    userPB,
  441.         const RecordID            *rid
  442.     );
  443. pascal Boolean                MyForEachAttrTypeLookup(
  444.         long                    userPB,
  445.         const AttributeType        *parmPtr,
  446.         AccessMask                myAttrAccMask
  447.     );
  448. pascal Boolean                MyForEachAttrValue(
  449.         long                    userPB,
  450.         const Attribute            *parmPtr
  451.     );
  452. pascal Boolean                MyForEachAttrType(
  453.         long                    userPB,
  454.         const AttributeType        *parmPtr
  455.     );
  456. pascal Boolean                GetPABFSSpecCB(
  457.         FSSpec                    *pabSpec,
  458.         const Attribute            *thisAttribute
  459.     );
  460. OSErr                        AddCatalog(
  461.         DTSSampleCSAMInfoPtr    infoPtr,
  462.         DirParamBlockPtr        pb
  463.     );
  464. OSErr                        RemoveCatalog(
  465.         DTSSampleCSAMInfoPtr    infoPtr,
  466.         DirParamBlockPtr        pb
  467.     );
  468. OSErr                        GetRefNumFromRLI(
  469.         DTSSampleCSAMInfoPtr    infoPtr,
  470.         PackedRLI                *prli,
  471.         short                    *refNum
  472.     );
  473. /*
  474.  * Interface to the Directory Manager functions.
  475.  */
  476. pascal OSErr                ADASOpenPAB(
  477.         FSSpec                    *spec,
  478.         char                    permissionsRequested,
  479.         short                    *refNum
  480.     );
  481. pascal OSErr                ADASClosePAB(
  482.         short                    refNum
  483.     );
  484. pascal OSErr                ADASGetOCESetupInfo(
  485.         RecordID                *rid,
  486.         short                    *refNum
  487.     );
  488. pascal OSErr                ADASLookupAttributeValue(
  489.         RecordID                *rid,
  490.         short                    dsRefNum,
  491.         AuthIdentity            identity, 
  492.         long                    bufferSize,
  493.         Boolean                    includeStartingPoint,
  494.         AttributeType            *attrType, 
  495.         const AttributeCreationID *attrCID, 
  496.         long                    clientData,
  497.         ForEachAttrValue        eachAttrValue
  498.     );
  499.  
  500. #endif    /* IsResource == 0        */
  501. #endif    /* __DTSSampleCSAM__    */
  502.  
  503.